package com.mrd.gtimp.service.client;

import com.mrd.constant.SystemConstants;
import com.mrd.gtimp.service.ISupDeclarationBizService;
import com.mrd.gtimp.service.dto.SupBaseBizQueryDTO;

import net.sf.json.JSONObject;

import org.apache.commons.lang3.StringUtils;
import org.apache.cxf.interceptor.LoggingInInterceptor;
import org.apache.cxf.interceptor.LoggingOutInterceptor;
import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;

public class SupBizServiceClient {

    JaxWsProxyFactoryBean factory;

    public SupBizServiceClient() {
        factory = new JaxWsProxyFactoryBean();
        factory.getInInterceptors().add(new LoggingInInterceptor());
        factory.getOutInterceptors().add(new LoggingOutInterceptor());
    }

    /**
     * 获取新港的柜号信息
     */
    public String declarationGetContainerInfo(SupBaseBizQueryDTO qdto) throws Exception {
        if (null == qdto || StringUtils.isEmpty(qdto.getServiceUrl())) {
            return null;
        }
        String serviceUrl = qdto.getServiceUrl();
        factory.setAddress(serviceUrl);
        ISupDeclarationBizService supBizService = factory.create(ISupDeclarationBizService.class);
        String paramsJson = JSONObject.fromObject(qdto).toString();
        String result = supBizService.findDeclarationContainerInfo(paramsJson);
        return result;
    }

    public static void main(String[] args) {
        SupBizServiceClient client = new SupBizServiceClient();
        SupBaseBizQueryDTO qdto = new SupBaseBizQueryDTO();
        //qdto.setServiceUrl("http://www.chuanhuoe.com:19080/cams/ws/supDeclarationBizService?wsdl");
        String serviceUrl = SystemConstants.SERVICE_URL_8080;
        System.out.println("declarationDownloadPath=serviceUrl=========" + serviceUrl);
        qdto.setServiceUrl(serviceUrl);
        qdto.setBizPk("896057969");
        //qdto.setBizPk("DRYU2978954");
        //qdto.setWork_type("0");
        try {
            String containerInfo = client.declarationDownloadPath(qdto);
            System.out.println("containerInfo=============" + containerInfo);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    /**
     * 黏贴柜号获取新港柜号
     */
    public String declarationGetPastContainerInfo(SupBaseBizQueryDTO qdto) throws Exception {
        if (null == qdto || StringUtils.isEmpty(qdto.getServiceUrl())) {
            return null;
        }
        String serviceUrl = qdto.getServiceUrl();
        factory.setAddress(serviceUrl);
        ISupDeclarationBizService supBizService = factory.create(ISupDeclarationBizService.class);
        String paramsJson = JSONObject.fromObject(qdto).toString();
        String result = supBizService.findDeclarationPastContainerInfo(paramsJson);
        return result;
    }

    /**
     * 查询报关底单下载的路径
     */
    public String declarationDownloadPath(SupBaseBizQueryDTO qdto) throws Exception {
        if (null == qdto || StringUtils.isEmpty(qdto.getServiceUrl())) {
            return null;
        }
        String serviceUrl = qdto.getServiceUrl();
        factory.setAddress(serviceUrl);
        ISupDeclarationBizService supBizService = factory.create(ISupDeclarationBizService.class);
        String paramsJson = JSONObject.fromObject(qdto).toString();
        String result = supBizService.findDeclarationDownloadPath(paramsJson);
        return result;
    }

}
